<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use Jedrzej\Pimpable\PimpableTrait;


class Cart extends Model
{
    use HasFactory;
    use PimpableTrait;
    use SoftDeletes;

    /**
     * 表中的类型状态 无
     */

    /**
     * 可搜索字段
     */
    public $searchable = [
        'product_id',
        'order_id',
        'combination_id',
        'seckill_id',
        'bargain_id',
        'type',
        'product_attr_unique'
    ];

    /**
     * 可批量赋值字段
     */
    public $fillable = ['product_num'];

    /**
     * 可排序字段
     */
    public $sortable = ['created_at', 'id'];

    /**
     * 默认排序字段
     */
    protected $defaultSortCriteria = ['id,desc'];


    /**
     * 购物车所属用户
     */
    function user(){
        return $this->belongsTo(User::class,'user_id','id');
    }
    /**
     * 购物车中的普通商品
     */
    function product(){
        return $this->belongsTo(Product::class,'product_id','id');
    }
//    /**
//     * 购物车中的普通商品
//     */
//    function order(){
//        return $this->belongsTo(Order::class,'order_id','id');
//    }
    /**
     * 购物车关联的拼团
     */
    function combination(){
        return $this->belongsTo(StorePink::class,'combination_id','id');
    }
    /**
     * 购物车关联的秒杀
     */
    function seckill(){
        return $this->belongsTo(StoreSeckill::class,'seckill_id','id');
    }
    /**
     * 购物车关联的砍价
     */
    function bargain(){
        return $this->belongsTo(StoreBargain::class,'bargain_id','id');
    }
}
